<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增公司主数据')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-company-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">公司编码：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="compCode" id="compCode" placeholder="请输入公司编码" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">公司名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="compName" placeholder="请输入公司名称" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">公司简称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="compAbbr" placeholder="请输入公司简称">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">上级公司：</label>
            <div class="col-sm-8">
                <select name="parentId" class="form-control m-b">
                    <option value="">请选择</option>
                    <option th:each="parent : ${parent}" th:text="${parent.compCN}"
                            th:value="${parent.id}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">所属集团：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="compGroup" placeholder="请输入所属集团" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">公司状态：</label>
            <div class="col-sm-8">
                <div class="check-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                    <input type="radio" name="status" th:value="${dict.dictValue}" th:checked="${dict.dictValue=='0'}"
                           th:text="${dict.dictLabel}">
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script>
    var prefix = ctx + "company";

    $("#form-company-add").validate({
        rules: {
            onkeyup: false,
            compCode: {
                remote: {
                    url: prefix + "/checkCodeUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "compCode": function () {
                            return $("input[name='compCode']").val();
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            }
        },
        messages: {
            "compCode": {
                remote: "公司编号已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-company-add").serializeArray();
            $.operate.save(prefix + "/add", data);
        }
    }

</script>
</body>
</html>